package org.liuhy.line.rect
{
	import org.liuhy.line.AbstractLine;
	import org.liuhy.line.CLine;
	import org.liuhy.node.FlowNode;
	import org.liuhy.node.focus.FocusNode;
	
	public class FocusUtils
	{
		public function FocusUtils()
		{
		}
		public function pos1(p_focusNode:FocusNode,p_line:AbstractLine,p_flowNode:FlowNode):Boolean{
			var _cLine:CLine = p_line.parent as CLine;
			if(p_focusNode.x+p_flowNode._x >(_cLine.x+ p_line.x1)){
				return true;
			}else{
				return false;
			}
		}
		public function _focusNodeArrowLine(p_focusNode:FocusNode,p_line:AbstractLine,p_flowNode:FlowNode,p_function:Function):void{
			var _cLine:CLine = p_line.parent as CLine;
			//竖线;
			if(p_line.x1 == p_line.x2){				
				if(pos1(p_focusNode,p_line,p_flowNode)){
					var _line1:RectLine = new RectLine(p_line.x1,p_focusNode.y+p_flowNode._y-_cLine.y,p_focusNode.x+p_flowNode._x-_cLine.x,p_focusNode.y+p_flowNode._y-_cLine.y,_cLine);
					var _line2:RectLine = new RectLine(p_line.x1,p_line.y1,_line1.x1,_line1.y1,_cLine);
					p_function.apply(null,[p_focusNode,p_line,[_line2,_line1],[p_line],p_line.preLine,null]);
				}else{
					//箭头线在流程左侧节点的右侧;
					if(null!=p_line.preLine){
						var _line1:RectLine = new RectLine(p_focusNode.x+p_flowNode._x-_cLine.x-RectConstants._ADJUST_LEN,p_focusNode.y + p_flowNode._y-_cLine.y,p_focusNode.x+p_flowNode._x-_cLine.x,p_focusNode.y + p_flowNode._y-_cLine.y,_cLine);								
						var _line2:RectLine = new RectLine(_line1.x1,p_line.y1,_line1.x1,_line1.y1,_cLine);	
						var _line3:RectLine = new RectLine(p_line.preLine.x1,p_line.preLine.y1,_line2.x1,_line2.y1,_cLine);
						p_function.apply(null,[p_focusNode,p_line,[_line3,_line2,_line1],[p_line.preLine,p_line],p_line.preLine.preLine,null]);
					}else{
						var _line1:RectLine = new RectLine(p_focusNode.x+p_flowNode._x-_cLine.x-RectConstants._ADJUST_LEN,p_focusNode.y + p_flowNode._y-_cLine.y,p_focusNode.x+p_flowNode._x-_cLine.x,p_focusNode.y + p_flowNode._y-_cLine.y,_cLine);
						var _y2:int = p_line.y1 + (p_line.y2-p_line.y1)/2;//
						var _line2:RectLine = new RectLine(_line1.x1,_y2,_line1.x1,_line1.y1,_cLine);	
						var _line3:RectLine = new RectLine(p_line.x1,_y2,_line2.x1,_line2.y1,_cLine);
						var _line4:RectLine = new RectLine(p_line.x1,p_line.y1,_line3.x1,_line3.y1,_cLine);
						p_function.apply(null,[p_focusNode,p_line,[_line4,_line3,_line2,_line1],[p_line],p_line.preLine,null]);
					}
				}
			}else if(p_line.y1	==	p_line.y2){
				//横线;
				if(pos1(p_focusNode,p_line,p_flowNode)){
					//一条横线;
					if(null==p_line.preLine){
						//x点选择有问题；
						var _x2:int = p_line.x1+ (p_focusNode.x + p_flowNode._x-_cLine.x -p_line.x1)/2;//
						
						var _line1:RectLine = new RectLine(_x2,p_focusNode.y + p_flowNode._y-_cLine.y,p_focusNode.x+p_flowNode._x-_cLine.x,p_focusNode.y + p_flowNode._y-_cLine.y,_cLine);
						var _line2:RectLine = new RectLine(_x2,p_line.y2,_line1.x1,_line1.y1,_cLine);	
						var _line3:RectLine = new RectLine(p_line.x1,p_line.y1,_line2.x1,_line2.y1,_cLine);
						p_function.apply(null,[p_focusNode,p_line,[_line3,_line2,_line1],[p_line],p_line.preLine,null]);
					}else{
						var _line1:RectLine = new RectLine(p_line.x1,p_focusNode.y + p_flowNode._y-_cLine.y,p_focusNode.x+p_flowNode._x-_cLine.x,p_focusNode.y + p_flowNode._y-_cLine.y,_cLine);
						var _line2:RectLine = new RectLine(p_line.preLine.x1,p_line.preLine.y1,_line1.x1,_line1.y1,_cLine);	
						p_function.apply(null,[p_focusNode,p_line,[_line2,_line1],[p_line.preLine,p_line],p_line.preLine.preLine,null]);
					}
				}else{
					//这个算法有待改善
					var _line1:RectLine = new RectLine(p_focusNode.x+p_flowNode._x-_cLine.x-RectConstants._ADJUST_LEN,p_focusNode.y + p_flowNode._y-_cLine.y,p_focusNode.x+p_flowNode._x-_cLine.x,p_focusNode.y + p_flowNode._y-_cLine.y,_cLine);
					var _y2:int = p_line.y1 + (p_line.y2-p_line.y1)/2;//
					var _line2:RectLine = new RectLine(_line1.x1,p_line.y1,_line1.x1,_line1.y1,_cLine);	
					var _line3:RectLine = new RectLine(p_line.x1,p_line.y1,_line2.x1,_line2.y1,_cLine);
					p_function.apply(null,[p_focusNode,p_line,[_line3,_line2,_line1],[p_line],p_line.preLine,null]);
				}				
			}
		}
		public function _focusNodeFromLine(p_focusNode:FocusNode,p_line:AbstractLine,p_flowNode:FlowNode,p_function:Function):void{
			
		}

	}
}